<?
//获取当前权限
session_start();
$vip = $_SESSION['userterm_web'];


/*原来旧版用的是直接传递过来的nid,addslashes($_REQUEST ['nid']); */
/*现在这个是经由route文件传过来的nid */
$trans_nid = $route_nid;

$nowTime = strtotime(date("Y-m-d H:i:s"));


//分类id存在，统计数目就是统计relation表格，因为relation有term_id项目
if ($trans_nid) {

//设置需要搜索的表格的前缀后缀
    $table_Suffix = "relation";
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀


//设置需要搜索的表格的排序项和升降项
    $sort_by = "listorder";
    $sort_order = "desc";
//设置需要搜索的表格的排序项和升降项

    if($vip==2){
        $query = mysql_query("SELECT COUNT(nid) FROM $table where term_nid = '$trans_nid' ");
        $resultsum = mysql_query("select * from $table where term_nid = '$trans_nid'");
    }else if($vip==1){
        $query = mysql_query("SELECT COUNT(nid) FROM $table where term_nid = '$trans_nid' and vip_term in (0,1)");
        $resultsum = mysql_query("select * from $table where term_nid = '$trans_nid' and vip_term in (0,1)");
    }else{
        $query = mysql_query("SELECT COUNT(nid) FROM $table where term_nid = '$trans_nid' and vip_term = '0'");
        $resultsum = mysql_query("select * from $table where term_nid = '$trans_nid' and vip_term = '0'");
    }

    $relation_sum = mysql_result($query, 0);

    while ($row = mysql_fetch_array($resultsum)) {
        $relation_detail_nid[] = $row['detail_nid'];
    }


    $table_Suffix = "detail";
    $tableDetail = $table_Prefix . $table_Suffix;

    $s=0;
    for($n=0;$n<$relation_sum;$n++){
        $query_publish = mysql_query("SELECT COUNT(nid) FROM $tableDetail where (nid = '$relation_detail_nid[$n]' and publish = '1') ");
        $relation_publish = mysql_result($query_publish, 0);
        if($relation_publish==1){
            $s++;
        }
    }
    $sum=$s;


} else {

//设置需要搜索的表格的前缀后缀
    $table_Suffix = "detail";
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀


//设置需要搜索的表格的排序项和升降项
    $sort_by = "listorder";
    $sort_order = "desc";
//设置需要搜索的表格的排序项和升降项

    if($vip==2){
        $query = mysql_query("SELECT COUNT(nid) FROM $table where belong = '$system_part' and publish = '1' and inputtime < $nowTime");
    }else if($vip==1){
        $query = mysql_query("SELECT COUNT(nid) FROM $table where belong = '$system_part' and publish = '1' and vip_term in (0,1) and inputtime < $nowTime");
    }else{
        $query = mysql_query("SELECT COUNT(nid) FROM $table where belong = '$system_part' and publish = '1' and vip_term = '0' and inputtime < $nowTime");
    }


    $sum = mysql_result($query, 0);
}




?>
















<?

//读取出传递过来的分类id下面，属于这个分类的detail数据


//设置需要搜索的表格的前缀后缀
$table_Suffix = $sys_list_table;
$table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀


//设置需要搜索的表格的排序项和升降项
$sort_by = "listorder";
$sort_order = "desc";
//设置需要搜索的表格的排序项和升降项


if (addslashes($_REQUEST ['sortby'])) {
    $sort_by = addslashes($_REQUEST ['sortby']);
}


if (addslashes($_REQUEST ['sortorder'])) {
    $sort_order = addslashes($_REQUEST ['sortorder']);

}

?>





<?php


$nowpageid = 1; //当前页数
$detailnum = $page_list_num; //每页显示多少个产品,$page_list_num在sys_info中定义的，每个板块都有可以独立设置


//翻页时候用到。如果有没有传递过来，打开第几页，就当第一页处理
if ($_REQUEST ['nowpageid']) {
    $nowpageid = $_REQUEST ['nowpageid'];
} else {
    $nowpageid = 1;
}


//翻页的时候，计算一下结果，应该从数据库的哪条条数据开始显示
$detailstar = ($nowpageid - 1) * $detailnum;


//$sums是搜索出来的结果，这里处理一下页面数.
if ($sum) //如果总数不等于0的话
{

    if ($sum < $detailnum) {
        $page_count = 1;
        $detailnum = $sum;
    } //如果总数据量小于$detailnum,detailnum作为每页显示数据的条数，）那么只有一页,而detailnum也更改为sum 


    else if ($sum % $detailnum) {
        $page_count = (int)($sum / $detailnum) + 1;
    }
    //取总数据量除以每页数的余数 
    //如果有余数，则页数等于总数据量除以每页数的结果取整再加一


    else {
        $page_count = $sum / $detailnum;
    }
    //如果没有余数，则页数等于总数据量除以每页数的结果 

} else //如果总数等于0的
{
    $page_count = 0;
    $detailnum = 0;
}


$lastpage = $page_count;
$prepage = $nowpageid - 1;
$nextpage = $nowpageid + 1;


//如果现在是第一页，上一页的页码被重置为0
if ($nowpageid == 1) {
    $prepage = 1;
}

//如果现在是最后一页
if ($nowpageid == $page_count) {

    if ($sum <= $detailnum) //数据的总条数少于每页显示数目，就把每页显示的数据（循环用）改成总数数目sum
    {
        $detailnum = $sum;
        $nextpage = $nowpageid;
    } else //现在是最后一页，并且总数数目大于循环数
    {
        $nextpage = $nowpageid; //重定义下一页为本页。因为是最后一页
        $detailnum = fmod($sum, $detailnum); //因为最后一页不一定是整好显示完(sum不一定能整除detailnum)，所以循环数是用余数的值
        if ($detailnum == 0) //这个if是因为当数据正好30条，能除尽的话，最后一页就会因为fmod能整除的缘故，最后一页不显示数据
        {
            $detailnum = $page_list_num;
        }
    }
    //如果现在页数等于总页数（总页数上面求出，最后一页不够循环数的时候），那么最后一页的detailnum就会等于余下数据(不足一页)的数目.

}

?>



<?

//开始搜索对应的detail资料


//设置需要搜索的表格的前缀后缀
$table_Suffix = "detail";
$table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀


//设置需要搜索的表格的排序项和升降项
$sort_by = "listorder";
$sort_order = "desc";
//设置需要搜索的表格的排序项和升降项

if (addslashes($_REQUEST ['sortby'])) {
    $sort_by = addslashes($_REQUEST ['sortby']);
}


if (addslashes($_REQUEST ['sortorder'])) {
    $sort_order = addslashes($_REQUEST ['sortorder']);
}


//加入有传递过来的id的话，就会出现这种情况
if ($trans_nid) {

//设置需要搜索的表格的前缀后缀
    $table_Suffix = "relation";
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀

    $result = mysql_query("select * from $table where term_nid = '$trans_nid'");

    while ($row = mysql_fetch_array($result)) {
        $relation_nid[] = $row['detail_nid'];
    }


//设置需要搜索的表格的前缀后缀
    $table_Suffix = 'detail';
    $table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀


    $relation_detail_str_1 = "select * from $table where ";

    for ($i = 0; $i < count($relation_nid); $i++) {
        if ($i != 0) {
            $relation_detail_str_2 = $relation_detail_str_2 . ' or ';
        }

        $relation_detail_str_2 = $relation_detail_str_2 . "nid=" . $relation_nid[$i];


    }


    if($vip==2){
        $relation_detail_str_3 = "";
    }else if($vip==1){
        $relation_detail_str_3 = " and vip_term in (0,1)";
    }else{
        $relation_detail_str_3 = " and vip_term = '0'";
    }

    $relation_detail_str_4 = " and publish = '1' and belong = '$sys_belong' and inputtime < $nowTime ORDER BY $sort_by $sort_order,nid $sort_order limit $detailstar , $detailnum";

    $result = mysql_query($relation_detail_str_1 ."(". $relation_detail_str_2 .")". $relation_detail_str_3 . $relation_detail_str_4);


} else {

    if($vip==2){
        $result = mysql_query("select * from $table where belong = '$sys_belong' and publish = '1' and inputtime < $nowTime ORDER BY $sort_by $sort_order,nid $sort_order limit $detailstar , $detailnum");
    }else if($vip==1){
        $result = mysql_query("select * from $table where belong = '$sys_belong' and publish = '1' and vip_term in (0,1) and inputtime < $nowTime ORDER BY $sort_by $sort_order,nid $sort_order limit $detailstar , $detailnum");
    }else{
        $result = mysql_query("select * from $table where belong = '$sys_belong' and publish = '1' and vip_term = '0' and inputtime < $nowTime ORDER BY $sort_by $sort_order,nid $sort_order limit $detailstar , $detailnum");
    }
}


while ($row = mysql_fetch_array($result)) {
    $detail_nid[]           = $row['nid'];
    $detail_mid[]           = $row['mid'];
    $detail_name[]          = $row['name'];
    $detail_title[]         = $row['title'];
    $detail_keyword[]       = $row['keyword'];
    $detail_description[]   = $row['description'];
    $detail_url[]           = $row['url'];


    $detail_model[]         = $row['model'];
    $detail_introduce[]     = $row['introduce'];
    $detail_detail[]        = $row['detail'];
    $detail_stock[]         = $row['stock'];
    $detail_price[]         = $row['price'];
    $detail_memberprice[]   = $row['memberprice'];
    $detail_discountprice[] = $row['discountprice'];
    $detail_local[]         = $row['local'];
    $detail_listorder[]     = $row['listorder'];


    $detail_hotsale[]       = $row['hotsale'];
    $detail_discount[]      = $row['discount'];
    $detail_recommend[]     = $row['recommend'];
    $detail_soldout[]       = $row['soldout'];
    $detail_publish[]       = $row['publish'];
    $detail_clickrate[]     = $row['clickrate'];
    $detail_onsaletime[]    = $row['onsaletime'];
    $detail_inputtime[]     = $row['inputtime'];
    $detail_modifytime[]    = $row['modifytime'];


    $detail_icon[]          = $row['icon'];
    $detail_storage[]       = $row['storage'];
    $detail_attachment[]    = $row['attachment'];
    $detail_image1[]        = $row['image1'];
}
mysql_close($con);

?>





<?

//读取出传递过来的分类id，读取分类的资料


//设置需要搜索的表格的前缀后缀
$table_Suffix = $sys_term_table;
$table = $table_Prefix . $table_Suffix;


//搜索传递过来的nid或者属于这个板块资料中最小值的nid,还要发布了的
//还要在该分类中增加点击率
$result = mysql_query("SELECT * FROM $table where nid = '$trans_nid' or nid = (select min(nid) from $table where belong ='$sys_belong') and publish = '1'");


while ($row = mysql_fetch_array($result)) {
    $term_nid = $row['nid'];
    $term_name = $row['name'];
    $term_title = $row['title'];
    $term_keyword = $row['keyword'];
    $term_description = $row['description'];
    $term_url = $row['url'];

    $term_model = $row['model'];
    $term_introduce = $row['introduce'];


    $term_clickrate = $row['clickrate'];
    $term_inputtime = $row['inputtime'];
    $term_modifytime = $row['modifytime'];

    $term_icon = $row['icon'];

    $term_image1 = $row['image1'];
    $term_image2 = $row['image2'];
    $term_image3 = $row['image3'];
    $term_image4 = $row['image4'];
    $term_image5 = $row['image5'];

}


mysql_close($con);

?>




